package com.admin.model;

import java.util.List;

import com.admin.util.UtilTools;

public class Roles extends MyDB<Roles> {
	public static final Roles dao = new Roles();
	public Roles(){
		tableName = "sys_roles";
	}
	
	// 设置权限
	public boolean batchAdd(Long roleId,String funIds){
		String sql = "delete from sys_role_function where role_id ="+roleId;
		dao.operateBySql(sql);
		if(null != funIds && funIds != ""){
			StringBuffer sb = new StringBuffer();
			sb.append(" insert into sys_role_function(function_id,role_id) values ");
			for(String funId : funIds.split(",")){
				if(!funId.equals("0")){
					sb.append(" ("+ funId +","+ roleId +") "+",");
				}
			}
			return dao.operateBySql(sb.substring(0,sb.length()-1));
		}
		return true;
	}
	
	/**
	 * 根据主键id批量删除
	 * @param ids
	 * @return
	 */
	public boolean del(String[] ids){
		String sql1 = "delete from sys_role_function where role_id in ("+ UtilTools.getStr(ids) +")";
		boolean result = this.operateBySql(sql1);
		if(result){
			String sql = "delete from sys_roles where id in ("+ UtilTools.getStr(ids) +")";
			return this.operateBySql(sql);
		}
		return false;
	}
}
